import java.util.*;

public class Test {


    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String s : tokens) {
            if(!isOperations(s)) {
                //不是运算符 是数字
                stack.push(Integer.parseInt(s));
            }else {
                //是运算符，所以得拿出2个数据
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(s) {
                    case "+":
                        stack.push(num1 + num2);
                        break;
                    case "-":
                        stack.push(num1 - num2);
                        break;
                    case "*":
                        stack.push(num1 * num2);
                        break;
                    case "/":
                        stack.push(num1 / num2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    private boolean isOperations(String oper) {
        if(oper.equals("+") || oper.equals("-") || oper.equals("*") ||oper.equals("/") ) {
            return true;
        }
        return false;
    }

    public boolean isValid(String s) {

        Stack<Character> stack = new Stack<>();

        for(int i = 0;i < s.length();i++) {
            char ch = s.charAt(i);
            if(ch == '(' || ch == '[' || ch == '{') {
                stack.push(ch);
            }else {
                if(stack.empty()) {
                    return false;
                }
                char ch2 = stack.peek();//左括号   此时ch当中是右括号
                if( ch2 == '(' && ch == ')' || ch2 == '[' && ch == ']'
                        || ch2 == '{' && ch == '}' ) {
                    //当前 左括号和右括号匹配
                    stack.pop();
                }else {
                    return false;
                }
            }
        }

        if(!stack.empty()) {
            return false;
        }

        return true;

    }

    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        int i = 0;
        for(; i < pushV.length;i++) {
            stack.push(pushV[i]);
            while(!stack.empty() && j < popV.length&&stack.peek() == popV[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(12);
        myStack.push(23);
        myStack.push(34);
        myStack.push(45);

        System.out.println(myStack.pop());//45
        System.out.println(myStack.peek());//34
        System.out.println(myStack.size());//3
        System.out.println(myStack.isEmpty());

        LinkedList<Integer> stack = new LinkedList<>();

    }


    public static void main3(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(12);
        stack.push(23);
        stack.push(34);
        stack.push(45);

        System.out.println(stack.pop());//45
        System.out.println(stack.peek());//
        System.out.println(stack.peek());//
    }

    public static void main2(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        System.out.println(list);
        System.out.println("===================");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("===================");
        for(int x : list) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("===================");

        Iterator<Integer> it = list.iterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("===================");
        ListIterator<Integer> lit = list.listIterator();
        while (lit.hasNext()) {
            System.out.print(lit.next()+" ");
        }
        System.out.println();
        System.out.println("===================");
        ListIterator<Integer> lit2 = list.listIterator(list.size());
        while (lit2.hasPrevious()) {
            System.out.print(lit2.previous()+" ");
        }
        System.out.println();

    }
    public static void main1(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(0,3);

        System.out.println(list);

        List<Integer> list1 = new ArrayList<>();
        list1.add(10);
        list1.add(20);
        list1.add(30);

        list.addAll(list1);

        System.out.println(list);

        list.clear();


    }
}
